﻿using System;
using System.Collections.Generic;
using System.Web;
using PayRoller.Code;
using System.Web.SessionState;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using HySoft.Cash.Business;
using HySoft.Cash.Structure;
using System.Configuration;
using System.Web.Profile;

namespace PayRoller.Manage.OrgInfo
{
    public class MyProfileUpt : ParentPage, IRequiresSessionState
    {
        // Fields
        protected Button bnSave;
        protected HtmlForm form1;
        protected Label lblTip;
        public string OrgSid = "";
        protected TextBox txtAltEmail1;
        protected TextBox txtAltEmail2;
        protected TextBox txtContactPerson;
        protected TextBox txtContactPhone1;
        protected TextBox txtContactPhone2;
        protected TextBox txtFax;
        protected TextBox txtMobile;
        protected TextBox txtPostalAddress;
        protected TextBox txtPreferredEmail;
        protected TextBox txtsPosition;

        // Methods
        protected void bnSave_Click(object sender, EventArgs e)
        {
            try
            {
                this.OrgSid = base.Request["OrgSid"].ToString();
                TorginfoBN obn = new TorginfoBN(this.Page);
                TorginfoDT detail = obn.Get(Convert.ToInt32(this.OrgSid));
                detail.Sid = Convert.ToInt32(this.OrgSid);
                detail.ContactPerson = this.txtContactPerson.Text;
                detail.sPosition = this.txtsPosition.Text;
                detail.PostalAddress = this.txtPostalAddress.Text;
                detail.ContactPhone1 = this.txtContactPhone1.Text;
                detail.ContactPhone2 = this.txtContactPhone2.Text;
                detail.Fax = this.txtFax.Text;
                detail.Mobile = this.txtMobile.Text;
                detail.PreferredEmail = this.txtPreferredEmail.Text;
                detail.AltEmail1 = this.txtAltEmail1.Text;
                detail.AltEmail2 = this.txtAltEmail2.Text;
                obn.Edit(detail);
                obn.Dispose();
                obn = null;
                base.ClientScript.RegisterStartupScript(base.GetType(), "", "<script>alert('Success!');window.location='Index.aspx?OrgSid=" + this.OrgSid + "'</script>");
            }
            catch (Exception exception)
            {
                this.lblTip.Text = exception.Message;
            }
        }

        protected override void OnInit(EventArgs e)
        {
            base.m_ModuleCode = "0003";
            base.CheckLogin(true);
            base.CheckPerm();
            base.OnInit(e);
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (base.Request["OrgSid"] != "")
            {
                this.OrgSid = base.Request["OrgSid"].ToString();
                if (!this.Page.IsPostBack)
                {
                    try
                    {
                        TorginfoBN obn = new TorginfoBN(this.Page);
                        TorginfoDT odt = obn.Get(Convert.ToInt32(this.OrgSid));
                        this.txtContactPerson.Text = odt.ContactPerson;
                        this.txtsPosition.Text = odt.sPosition;
                        this.txtPostalAddress.Text = odt.PostalAddress;
                        this.txtContactPhone1.Text = odt.ContactPhone1;
                        this.txtContactPhone2.Text = odt.ContactPhone2;
                        this.txtFax.Text = odt.Fax;
                        this.txtMobile.Text = odt.Mobile;
                        this.txtPreferredEmail.Text = odt.PreferredEmail;
                        this.txtAltEmail1.Text = odt.AltEmail1;
                        this.txtAltEmail2.Text = odt.AltEmail2;
                        obn.Dispose();
                        obn = null;
                    }
                    catch (Exception exception)
                    {
                        this.lblTip.Text = exception.Message;
                    }
                }
            }
        }

        // Properties
        protected HttpApplication ApplicationInstance
        {
            get
            {
                return this.Context.ApplicationInstance;
            }
        }

        protected DefaultProfile Profile
        {
            get
            {
                return (DefaultProfile)this.Context.Profile;
            }
        }
    }

}
